package blog.com.mw.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import blog.com.mw.base.ResultData;
import blog.com.mw.pojo.vo.CategoryTypeVO;
import blog.com.mw.pojo.vo.CategoryVO;
import blog.com.mw.service.CategoryService;

@RestController
@RequestMapping("/category")
public class CategoryController {

	@Autowired
	private CategoryService service;
	
	@RequestMapping(value = "/categoryList",method = RequestMethod.GET)
	public ResultData getAllCategory() {
		ResultData rs = null ;
		rs = service.getAllCategory();
		return rs;
	}
	
	@RequestMapping(value = "/category",method = RequestMethod.GET)
	public ResultData getCategoryById(@RequestParam("id") int id,@RequestParam("isArticleId") Boolean isArticleId) {
		ResultData rs = null ;
		rs = service.getCategoryById(id, isArticleId);
		return rs;
	}
	
	@RequestMapping(value = "/category",method = RequestMethod.POST)
	public ResultData addCategory(@RequestBody CategoryVO vo) {
		ResultData rs = null ;
		rs = service.addCategory(vo);
		return rs;
	}
	
	@RequestMapping(value = "/category",method = RequestMethod.DELETE)
	public ResultData delCategory(@RequestParam("id") int id) {
		ResultData rs = null ;
		rs = service.delCategory(id);
		return rs;
	}
	
	
	@RequestMapping(value = "/categoryTypeList",method = RequestMethod.GET)
	public ResultData getAllCategoryType(@RequestParam(value = "page",required=false) String pageNum
			,@RequestParam(value = "limit",required=false) String pageSize
			,@RequestParam(value="keyword", required=false)String keyword) {
		ResultData rs = null ;
		rs = service.getAllCategoryType(pageNum,pageSize,keyword);
		return rs;
	}
	
	@RequestMapping(value = "/categoryType",method = RequestMethod.GET)
	public ResultData getCategoryTypeById(@RequestParam("id") int id) {
		ResultData rs = null ;
		rs = service.getCategoryTypeById(id);
		return rs;
	}
	
	@RequestMapping(value = "/getCategoryTypeByContent", method = RequestMethod.GET)
	public ResultData getCategoryTypeByContent(@RequestParam("content") String content) {
		ResultData rs = null;
		rs = service.getCategoryTypeByContent(content);
		return rs;
	}
	
	@RequestMapping(value = "/categoryType",method = RequestMethod.POST)
	public ResultData addCategoryType(@RequestBody CategoryTypeVO vo) {
		ResultData rs = null ;
		rs = service.addCategoryType(vo);
		return rs;
	}
	
	@RequestMapping(value = "/categoryType",method = RequestMethod.PUT)
	public ResultData updateCategoryType(@RequestBody CategoryTypeVO vo) {
		ResultData rs = null ;
		rs = service.updateCategoryType(vo);
		return rs;
	}
	
	@RequestMapping(value = "/categoryType/{id}",method = RequestMethod.DELETE)
	public ResultData delCategoryType(@PathVariable("id") int id) {
		ResultData rs = null ;
		List<Integer> ids = new ArrayList<>();
		ids.add(id);
		rs = service.delCategoryType(ids);
		return rs;
	}
	
	@RequestMapping(value = "/categoryType",method = RequestMethod.DELETE)
	public ResultData delCategoryTypeByIds(@RequestBody List<Integer> ids) {
		ResultData rs = null ;
		rs = service.delCategoryType(ids);
		return rs;
	}
}
